package com.sunmi.sbs.commons.utils;

import org.apache.commons.lang3.StringUtils;
import redis.clients.jedis.Jedis;

import java.util.HashMap;


/**
 * author: fanjia
 * date: 2020/12/15 15:21
 * file: JEDISUtils.java
 */
public class JEDISUtils {
    public static Jedis redisConnect(HashMap jedisProp) {
        Jedis jedis = new Jedis(jedisProp.get("host").toString(), Integer.parseInt(jedisProp.get("port").toString()));
        if (StringUtils.isNotBlank(jedisProp.get("password").toString())) {
            jedis.auth(jedisProp.get("password").toString());
        }
        return jedis;
    }


    public static String getResult(Jedis jedis, int index, String key) {
        jedis.select(index);
        return jedis.get(key);

    }

    public static Boolean sIsmember(Jedis jedis, int index, String key,String member){
        jedis.select(index);
        return jedis.sismember(key,member);
    }


    public static Long sCard(Jedis jedis, int index, String key){
        jedis.select(index);
        return jedis.scard(key);
    }

}
